package org.jackysoft.util;

import java.io.IOException;

import javax.servlet.ServletException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.ServletActionContext;

public final class SOAOfficeUtil {
	
	static final Log log = LogFactory.getLog(SOAOfficeUtil.class);
	
	public static byte[] parseSOAOfficeStream() {
		SOAOfficeX.SaveDocObj soa = new SOAOfficeX.SaveDocObj(ServletActionContext.getRequest(), ServletActionContext.getResponse());
		
		byte[] content = new byte[0];

		try {
           
			content = soa.getFileBytes();

		} catch (ServletException e) {
			
			log.error(e);
			e.printStackTrace();
		} catch (IOException e) {
			log.error(e);
			e.printStackTrace();
		} catch (Exception e) {
			log.error(e);
			e.printStackTrace();
		} finally {
			try {
				soa.returnOK();
				soa.close();
			} catch (IOException e) {
				log.error(e);
				e.printStackTrace();
			} catch (Exception e) {
				log.error(e);
				e.printStackTrace();
			}

		}
		return content;

	}
	
	public static  String requestFormField(String key){
		SOAOfficeX.SaveDocObj soa = new SOAOfficeX.SaveDocObj(ServletActionContext.getRequest(), ServletActionContext.getResponse());
		String value = "";
		try {
			value = soa.RequestFormField(key);
		} catch (IOException e) {
			log.error(e);
		} catch (Exception e) {
			log.error(e);
		}
		
		return value;
	}
}
